package models

import (
	"myRbac/utils"
	"time"
)

// 角色表结构体
type Role struct {
	// 角色Id
	Id int `json:"id" gorm:"column:id;type:int;auto_increment;primary_key;"`
	// 角色名
	Name string `json:"name" gorm:"column:name;type:varchar(40);"`
	// 角色标识
	Sign string `json:"sign" gorm:"column:sign;type:varchar(40);"`
	// 角色描述
	Description string `json:"description" gorm:"column:description;type:varchar(120);"`
	// 权限范围
	Scope int `json:"scope" gorm:"column:scope;type:int;"`
	// 状态
	Status int `json:"status" gorm:"column:status;type:int;"`
	// 创建时间
	CreateTime string `json:"create_time" gorm:"column:create_time;type:varchar(30);"`
	// 是否删除
	IsDelete int `json:"is_delete" gorm:"column:is_delete;type:int;"`
	// 创建权限关联表（建表的时候开一下，其他时候建议关掉，不关掉也没关系，使用json和form注释掉就可以）
	Menu []*Menu `json:"menus" form:"-" gorm:"many2many:role_menu;"`
	User []*User `json:"users" form:"-" gorm:"many2many:user_role;"`
}

// 插入一批角色数据
func InsertMockRoles() {
	DB.Model(&Role{}).Create([]Role{
		{Id: 1, Name: "超级管理员", Sign: "SUPERADMIN", Description: "超级管理员", Scope: 1, Status: 1, CreateTime: utils.TimeFormatter(time.Now()), IsDelete: 0},
		{Id: 2, Name: "普通管理员", Sign: "ADMIN", Description: "普通管理员", Scope: 2, Status: 1, CreateTime: utils.TimeFormatter(time.Now()), IsDelete: 0},
		{Id: 3, Name: "机构店长", Sign: "OWNER", Description: "机构店长", Scope: 3, Status: 1, CreateTime: utils.TimeFormatter(time.Now()), IsDelete: 0},
		{Id: 4, Name: "机构教师", Sign: "TEACHER", Description: "机构教师", Scope: 4, Status: 1, CreateTime: utils.TimeFormatter(time.Now()), IsDelete: 0},
		{Id: 5, Name: "机构学员", Sign: "STUDENT", Description: "机构学员", Scope: 5, Status: 1, CreateTime: utils.TimeFormatter(time.Now()), IsDelete: 0},
	})
}
